#include<iostream>
#include<vector>
using namespace std;


vector<int> searchRange(vector<int>& nums, int target) {
    vector<int> result;
    int minIndex = 0;
    int maxIndex = nums.size()-1;
    int firstPosition = -1;
    int lastPosition = -1;
    //找第一个等于target的位置
    while(minIndex<=maxIndex)
    {
        int midIndex = ((maxIndex - minIndex)>>1)+minIndex;    
        if(nums[midIndex] == target)
        {
            firstPosition = midIndex;
            maxIndex = midIndex-1;
        }else if(nums[midIndex] > target)
        {
            maxIndex = midIndex-1;
        }else{
            minIndex = midIndex+1;
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    }
    result.push_back(firstPosition);
    minIndex = 0;
    maxIndex = nums.size() - 1;
    while (minIndex <= maxIndex)
    {
       int midIndex = ((maxIndex - minIndex) >>1 ) + minIndex;
       if(nums[midIndex] == target)
       {
         lastPosition = midIndex;
         minIndex = midIndex + 1;
       }else if(nums[midIndex]<target)
       {
         minIndex = midIndex + 1;
       }else{
         maxIndex = midIndex - 1;  
       }
    }
    result.push_back(lastPosition);
    return result;
}
int main(){
    vector<int> v(6);
    int target;
    cout<<"Enter the numbers: "<<endl;
    for(int i=0;i<6;i++)
    {
        cin>>v[i];
    }
    cout<<"Enter the target number: "<<endl;
    cin>>target;
    vector<int> result=searchRange(v,target);
    cout<<"The result is: "<<result[0]<<" "<<result[1]<<endl;
    return 0;
}